﻿/**************************************************
 * Quantum Quest Game Project                     *
 *                                                *
 * Version:                                       *
 * Design 1.0                                     *
 *                                                *
 * Authors:                                       *
 * Michael Fowler                                 *
 * Michael Timmins                                *
 * Octavian Geagla                                *
 * Eric Cooper                                    *
 *                                                *
 * License:                                       *
 * Unknown                                        *
 *                                                *
 * ************************************************/

/**************************************************
 * QQList.cs                                      *
 *                                                *
 * Created:                                       *
 * 6/15/09, Octavian Geagla                       *
 *                                                *
 * Updated:                                       *
 * 6/15/09                                        *
 *                                                *
 * Description:                                   *
 * Standard List implementation that implements   *
 * the IList interface.  Can be used for level,   *
 * game object, and media containment.            *
 *                                                *
 * ************************************************/



using System;
using System.Collections;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace QuantumQuest
{
    public class QQList:IList
    {

        private int _iter;
        private int _size;
        private object[] _list;

        private bool _isFixedSize;
        private bool _isReadOnly;

        public QQList(int size)
        {
            _isFixedSize = false;
            _isReadOnly = false;
            _iter = 0;
            _size = size;
            _list = new object[_size];
        }
        public int Add(object obj)
        {
            if (_iter < _size)
            {
                _list[_iter] = obj;
                _iter++;
                return (_iter - 1);
            }
            else
            { 
                return -1;
            }         
        }
        public void Clear()
        {
            _iter = 0;
        }
        public bool Contains(object obj)
        {
            bool inList = false;
            for (int i = 0; i < _iter; i++)
            {
                if (_list[i] == obj)
                {
                    inList = true;
                    break;
                }
            }
            return inList;
        }
        public int IndexOf(object obj)
        {
            int index = -1;
            for (int i = 0; i < _iter; i++)
            {
                if (_list[i] == obj)
                {
                    index = i;
                    break;
                }             
            }
            return index;
        }
        public void Insert(int index, object obj)
        {
            if ((_iter + 1 <= _size) && (index < _iter) && (index >= 0))
            {
                _iter++;
                for (int i = _iter - 1; i > index; i--)
                {
                    _list[i] = _list[i - 1];
                }
                _list[index] = obj;
            }
        }
        public bool IsFixedSize
        {
            get
            {
                return _isFixedSize;
            }
            set
            {
                _isFixedSize = value;
            }
        }
        public bool IsReadOnly
        {
            get
            {
                return _isReadOnly;
            }
            set
            {
                _isReadOnly = value;
            }
        }
        public void Remove(object obj)
        {
            RemoveAt(IndexOf(obj));
        }
        public void RemoveAt(int index)
        {
            if ((index >= 0) && (index < _iter))
            {
                for (int i = index; i < _iter - 1; i++)
                {
                    _list[i] = _list[i + 1];
                }
                _iter--;
            }
        }
        public object this[int index]
        {
            get
            {
                return _list[index];
            }
            set
            {
                _list[index] = value;
            }
        }

        //ICollection stuff:

        public void CopyTo(Array array, int index)
        {
            int j = index;
            for (int i = 0; i < _iter; i++)
            {
                array.SetValue(_list[i], j);
                j++;
            }           
        }

        public int Count
        {
            get
            {
                return _iter;
            }
        }
        public bool IsSynchronized
        {
            get
            {
                return false;
            }
        }
        public object SyncRoot
        {
            get
            {
                return this;
            }
        }

        //IEnumerable stuff:

        public IEnumerator GetEnumerator()
        {
            throw new Exception("GetEnumerator will not be implemented, so don't use it; use Count for accessing _iter for lastest index in use.");
        }
       


    }
}
